package com.ruoyi.account.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.account.domain.AccountTrade;
import com.ruoyi.account.domain.WithdrawalAccount;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.account.mapper.AccountMapper;
import com.ruoyi.account.domain.Account;
import com.ruoyi.account.service.IAccountService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-03
 */
@Service
public class AccountServiceImpl implements IAccountService {
    @Autowired
    private AccountMapper accountMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public Account selectAccountById(Long id) {
        return accountMapper.selectAccountById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param account 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<Account> selectAccountList(Account account) {
        return accountMapper.selectAccountList(account);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param account 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertAccount(Account account) {
        account.setCreateTime(DateUtils.getNowDate());
        return accountMapper.insertAccount(account);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param account 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateAccount(Account account) {
        account.setUpdateTime(DateUtils.getNowDate());
        return accountMapper.updateAccount(account);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAccountByIds(Long[] ids) {
        return accountMapper.deleteAccountByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAccountById(Long id) {
        return accountMapper.deleteAccountById(id);
    }

    /**
     * 获取账户信息
     *
     * @param
     * @return 结果
     */
    @Override
    public Account getUserAccountMessage() {
        if (accountMapper.getUserAccountMessage(UserContext.get().getId()) == null) {
            Account account = new Account();
            account.setUserId(UserContext.getUserId());
            account.setDepositAccount(new BigDecimal("0.00"));
            account.setWithdrawableAccount(new BigDecimal("0.00"));
            accountMapper.insertUserAccountMessage(account);
        }
        return accountMapper.getUserAccountMessage(UserContext.get().getId());
    }

    /**
     * 获取账户账户流水信息
     *
     * @param
     * @return 结果
     */
    @Override
    public AccountTrade getUserAccountTradeMessage() {
        return accountMapper.getUserAccountTradeMessage(UserContext.getUserId());
    }
    /**
     * 新增用户账户充值信息
     *
     * @param
     * @return 结果
     */
    @Override
    public WithdrawalAccount insertWithdrawalAccountTradeMessage(String phone, String bankName, String bankNumber, String bankId, String ifsc, String email) {
        WithdrawalAccount withdrawalAccount = new WithdrawalAccount();
        withdrawalAccount.setUserId(UserContext.getUserId());
        withdrawalAccount.setPhone(phone);
        withdrawalAccount.setBankName(bankName);
        withdrawalAccount.setBankNumber(bankNumber);
        withdrawalAccount.setBankId(bankId);
        withdrawalAccount.setIfsc(ifsc);
        withdrawalAccount.setEmail(email);
        accountMapper.insertWithdrawalAccountTradeMessage(withdrawalAccount);
        return withdrawalAccount;
    }
}
